package org.example;

import com.sage.boot.SageApplication;
import com.sage.boot.SageBootApplication;
import com.sage.toolkit.net.InetUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

/**
 * Hello world!
 */
@SageBootApplication
@Slf4j
public class App {
    public static void main(String[] args) {
        ConfigurableApplicationContext context = SageApplication.run(App.class, args);
        logApplicationStartup(context.getEnvironment());
    }

    private static void logApplicationStartup(ConfigurableEnvironment env) {
        String protocol = "http";
        if (env.getProperty("server.ssl.key-store") != null) {
            protocol = "https";
        }

        String hostAddress = InetUtils.findFirstNonLoopbackAddress().getHostAddress();
        String serverPort = env.getProperty("server.port", "8080");
        String contextPath = env.getProperty("server.servlet.context-path", "/");
        log.info("{}://{}:{}{}", protocol, hostAddress, serverPort, contextPath);
    }
}
